﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.WebControls;

using FRL.DebtChased.Repository.PartModels;
using FRL.DebtChased.Website;
using FRL.DebtChased.Repository;

namespace FRL.DebtChased.Website.FinanceParts
{

	/// <summary>
	/// Declaration of FinWorkSummaryTable class
	/// </summary>
	public class FinWorkSummaryTable : BaseWebPart
	{

		/////////////////////////////////////////////////////////////
		// Attributes

		/////////////////////////////////////////////////////////////
		// Construction

		public FinWorkSummaryTable()
			:base("Work Summary", eMode.WithoutGrid)
		{

		}

		/////////////////////////////////////////////////////////////
		// Implementation

		protected override int ContentWidth
		{
			get { return 340; }
		}

		protected override int ContentHeight
		{
			get { return 0; }
		}

		protected override void _fillContent(System.Web.UI.HtmlTextWriter w, GridView gridView)
		{

			// Cast the model
			FinWorkSummaryModel model = m_model as FinWorkSummaryModel;

			// Build a table
			HtmlTableBuilder table = new HtmlTableBuilder("WorkSummary", 0, 0, 0, ContentWidth, ContentHeight, "PartTableStyle");
#if DEBUG
			table.Border = 1;
#endif // #if DEBUG
			table.SetCells(0, -1, "Overdue", "Today", "&nbsp;", "15-OCT", "18-OCT", "19-OCT", "20-OCT", "&nbsp;", "Future", "&nbsp;");
			table.SetCells(0, -1, "&nbsp;");
			table.SetCells(0, -1,
				model.SetA.Overdue.ToString(),
				model.SetA.Today.ToString(),
				"&nbsp;",
				model.SetA.Plus1.ToString(),
				model.SetA.Plus2.ToString(),
				model.SetA.Plus3.ToString(),
				model.SetA.Plus4.ToString(),
				"&nbsp;",
				model.SetA.Future.ToString(),
				"Calls"
			);
			table.SetCells(0, -1,
				model.SetB.Overdue.ToString(),
				model.SetB.Today.ToString(),
				"&nbsp;",
				model.SetB.Plus1.ToString(),
				model.SetB.Plus2.ToString(),
				model.SetB.Plus3.ToString(),
				model.SetB.Plus4.ToString(),
				"&nbsp;",
				model.SetB.Future.ToString(),
				"Auto"
			);
			table.SetStyle(0, 0, -1, 0, "PartLabelStyle");
			table.SetStyle(0, 1, -1, -1, "PartValueStyle");
			table.SetNoWrap();

			// Add to html
			w.Write(table.ToHtml());

		}

		protected override void _loadModel()
		{

			// Get repository
			DebtChasedEntities ent = base._getEnt();

			// Load the model
			m_model = new FinWorkSummaryModel(ent);

		}

	}

}